﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
using YBBEST.Office365Portal.Core;
using YBBEST.Office365Portal.CoreTests.Stubs;

namespace YBBEST.Office365Portal.CoreTests
{
    public class ServiceConnectionTest
    {
        [Fact]
        public void ConfigureAuthenticationRequestCookie_WithCookie_SetsHttpRequestMessagePropertyOnce()
        {
            // Arrange
            IProxyConfiguration configuration = new ProxyConfiguration();

            var builder = new HttpRequestMessageBuilderStub();
            IMsOnlineClaimsHelper msOnlineClaimsHelper=new MsOnlineClaimsHelperStub();
            var connectionBehavor = new ServiceConnection(configuration, builder,msOnlineClaimsHelper);
            msOnlineClaimsHelper.CookieContainer.SetCookies(new Uri(configuration.SiteUrl),"adfa" );

            // Act
            connectionBehavor.ConfigureAuthenticationRequestCookie();
            connectionBehavor.ConfigureAuthenticationRequestCookie();

            // Assert
            Assert.Equal(1,builder.TimesBuildCalled);
            Assert.Equal("adfa=", builder.Prop.Headers["Cookie"]);
        }

        
    }
}
